<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/4/14 0014
 * Time: 下午 14:03
 */

namespace Home\Model;
use Think\Model;

class SendMsgModel extends Model{
    //获取当前客户和客服的聊天信息
    public function get_msg($userid,$kefuid){
        $send = D()->query("select * from send_msg where send_id='{$userid}' and receiver_id='{$kefuid}'");
        $receiver = D()->query("select * from receiver_msg where send_id='{$kefuid}' and receiver_id='{$userid}'");
        $arr = array_merge($send,$receiver);
        $time = array_column($arr,'time');
        array_multisort($time,$arr);
        //dump($arr);exit;
        if(!$arr){
            $arr = false;
        }
        return $arr;
    }

    //取出当前客户消息的最大ID
    public function getmaxid($userid,$receiverid){
        $info = D()->query("select max(id) maxid from send_msg where send_id='{$userid}' and receiver_id='{$receiverid}'");
        return $info[0]['maxid'] ? $info[0]['maxid'] : 0;
    }


}